// components/comment-list/comment-list.js
var utils = require('../../utils/util.js');
Component({
  properties: {
    data: {
      type: null,
    },
    del: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    //商品详情
    noFrutisDetails11Tap: function(e) {
      var that = this;
      var id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pages/commoditydetails/commoditydetails?id=' + id,
      })
    },

    del: function(e) {
      var that = this;
      wx.showModal({
        title: '删除',
        content: '您确认要删除这条评论吗？',
        success: function(res) {
          if (res.confirm) {
            wx.showLoading();
            var id = e.currentTarget.dataset.id;
            var index = e.currentTarget.dataset.index;
            utils.http("/api/v1/member/del_my_comments", {
              id
            }, function() {
              that.data.data.splice(index, 1)
              that.setData({
                data: that.data.data,
              }, function() {
                that.triggerEvent('myevent', that.data.data);
                wx.hideLoading();
              })
            })
          }
        }
      })
    },
    // 点击cover播放，其它视频结束 
    videoPlay: function(e) {
      var audioCtx = wx.createVideoContext('myAudio');
      audioCtx.pause();
      var _index = e.currentTarget.id
      console.log(_index)
      this.setData({
        _index: _index
      })
      //停止正在播放的视频 
      var videoContextPrev = wx.createVideoContext(this.data._index)
      videoContextPrev.stop();
      setTimeout(function() { //将点击视频进行播放   
        var videoContext = wx.createVideoContext(_index)
        videoContext.play();
      }, 500)
    }
  }
})